package com.object;
import java.util.ArrayList;
import java.util.Scanner;

public class Sturcture {

    Scanner scanner = new Scanner(System.in);
    ArrayList<User> users = new ArrayList<>();//用户
    ArrayList<Item> items = new ArrayList<>();//商城商品
    ArrayList<Pet> pets= new ArrayList<>();//宠物 昵称 性别 年龄 种类 颜色
    ArrayList<LoginLog>loginLogs =new ArrayList<>();//登录日志
    ArrayList<OperateLog>operateLogs =new ArrayList<>();//操作日志
    User loginUser = new User();

    public void sturcture(){
        pets = new Pet().initPet(pets);//初始化宠物
        items = new Item().initData(loginUser,items);
        boolean isFlag = true;
        while (isFlag){
            System.out.println("请选择操作1:登录  2:注册  3:找回密码   4:退出");
            switch (scanner.next()){
                case "1":
                    User user = new User();
                    loginUser= user.login(users, loginLogs, scanner);
                    if(loginUser.getUid() != null){
                        sturctureIn(isFlag);
                    }
                    //登陆成功

                    break;
                case "2":
                    User user1 = new User();
                    users=user1.addUser(users,scanner);
                    break;
                case "3":
                    User user2 = new User();
                    users=user2.revisePassword(users,scanner);
                    break;
                case "4":
                    isFlag = false;
                    System.out.println("已退出");
                    break;
                default:
                    System.out.println("操作不合法，重新输入");
            }
        }
    }
    public void sturctureIn(boolean isFlag){
        boolean isOp=true;
        //登录成功
        while (isOp){
            System.out.println("请选择\n1:购买宠物\n2:查看购物车\n3:商城\n4:查看订单\n5:登录日志\n6:操作日志\n7:切换用户\n其他:退出");
            switch (scanner.next()){
                case "1":
                    new Pet().showPet(pets,operateLogs,loginUser);//展示商品
                    new Pet().buyPet(pets,operateLogs,loginUser,scanner);//购买商品
                    break;
                case "2":
                    new ShoppingCart().showShopping(operateLogs,loginUser,scanner,pets);//打印购物车
                    loginUser = new ShoppingCart().chooseShopping(operateLogs,loginUser, scanner,pets);//购物车内选择购买或删除
                    System.out.println(loginUser.getName());
                    break;
                case "3":
                    mall(true);
                    break;
                case "4":
                     loginUser = new Order().viewOrder(operateLogs, loginUser, scanner);//todo 打印订单
                    loginUser = new Order().orderChoose(loginUser, scanner,pets);//选择

                    break;
                case "5":
                    new LoginLog().viewLogin(loginLogs);
                    System.out.println("输入任意字符返回");
                    scanner.next();
                    break;
                case "6":
                    new OperateLog().viewOperate(operateLogs);
                    System.out.println("输入任意字符返回");
                    scanner.next();
                    break;
                case "7":
                    isOp=false;
                    break;
                default:
                    isFlag =false;
            }
            if (!isFlag){
                System.out.println("已退出系统");
                break;
            }
        }
    }
    public void mall(boolean isOp){
        while (isOp){
            System.out.println("欢迎进入商城  请选择:  1: 查看商品    2:购物车    3:订单   4:返回上一步");
        switch (scanner.next()){
            case "1":
                new Item().showItems( new Item().chooseType(scanner),items);
                while (true){
                    new Item().buy(items,loginUser,scanner);
                    if(!new Item().conAdd(scanner)){
                        break;
                    }
                }
                break;
            case "2":
                System.out.println("购物车");
                while (true){
                    new ItemCart().showItems(loginUser,scanner);
                    if(!new ItemCart().operate(scanner,loginUser,items)){
                        break;
                    }
                }
                break;
            case "3":
                System.out.println("订单");
                new ItemOrder().viewItemOrder(loginUser,scanner);
                System.out.println("petobj=   "+loginUser.petObj.toString());
                break;
            case "4":
                System.out.println("返回上一步");
                isOp =false;
                break;
            default:
                System.out.println("输入不合法请重新输入");
        }
            if (!isOp){
                break;
            }
        }
    }
}
